package com.mexico.inloancash.activity;


import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.TextView;

import com.google.gson.Gson;
import com.mexico.inloancash.R;
import com.mexico.inloancash.bean.India_User_PhoneList_Bean;
import com.mexico.inloancash.http.IndiaRequestApi;
import com.mexico.inloancash.http.IndiaDKFactory;
import com.mexico.inloancash.utils.IntentUtils;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

/**
 * 客服中心
 */
public class IndiaCustomerServiceActivity extends BaseActivity {

    @BindView(R.id.title)
    TextView title;

    @BindView(R.id.tvPhone)
    TextView mtvPhone;

    @BindView(R.id.tvEmail)
    TextView mTvEmail;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.india_activity_service_view_layout);
        ButterKnife.bind(this);
        title.setText("Customer Service");
        mIndia_GetContact();
    }

    @OnClick({R.id.logon_back})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.logon_back:
                finish();
                break;
        }
    }

    public void mIndia_GetContact() {
        Log.d("loan", "getService");
        IndiaRequestApi api = IndiaDKFactory.getInstance().getApi();
        Call<String> getService = api.getPhone();
        getService.enqueue(new Callback<String>() {
            @Override
            public void onResponse(Call<String> call, Response<String> response) {
                Log.d("loan", "getService onResponse:" + response.body());
                if (response.isSuccessful()) {
                    India_User_PhoneList_Bean bean = new Gson().fromJson(response.body(), India_User_PhoneList_Bean.class);
                    if (bean.getCode() == 200) {
                        mtvPhone.setText(bean.getData().getTelephone());
                        mTvEmail.setText(bean.getData().getE_mail());
                    }
                }
            }

            @Override
            public void onFailure(Call<String> call, Throwable t) {

            }
        });
    }

    @OnClick(R.id.tvPhone)
    public void clickPhone() {
        IntentUtils.openPhone(this, mtvPhone.getText().toString());
    }

    @OnClick(R.id.tvEmail)
    public void clickEmail() {
        IntentUtils.openEmail(this, mTvEmail.getText().toString());
    }
}
